package com.xianye.erp.scheduled;

import java.util.Calendar;
import javax.annotation.Resource;
import com.xianye.erp.service.order.impl.OrderService;
import com.xianye.erp.service.order.impl.RefreshOrderException;
import com.xianye.erp.service.order.impl.RefreshOrderService;
import com.xianye.erp.service.order.impl.RefreshOrderStatus;
import com.xianye.erp.service.product.impl.RefreshProductService;
import com.xianye.erp.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


//@Component
public class MyScheduled {
    protected Logger log = LoggerFactory.getLogger(MyScheduled.class);
    @Resource(name="refreshProductService")
    private RefreshProductService refreshProductService;
    @Resource(name="refreshOrderService")
    private RefreshOrderService refreshOrderService;
    @Resource(name="refreshOrderStatus")
    private RefreshOrderStatus refreshOrderStatus;
    @Resource(name="orderService")
    private OrderService orderService;
    @Resource(name="refreshOrderException")
    private RefreshOrderException refreshOrderException;
    

   // @Scheduled(cron="0 0 12 * * ?")
    public void refreshProduct() {
        // 间隔12小时,执行商品同步
        try {
        refreshProductService.refresh();
        log.info("同步商品数据 product");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
   // @Scheduled(cron="0 0/1 * * * ?")
    public void refreshOrder() {
        // 间隔0.5小时,执行订单同步
        try {
        	Calendar now =Calendar.getInstance();
        	now.set(Calendar.DATE, now.get(Calendar.DATE)-10);
        	//System.out.println(now.getTime().toLocaleString());
            String start = DateUtil.getDayStr("MM/dd/yyyy",now.getTime())+" 00:00:01";
            String end = DateUtil.getDayStr("MM/dd/yyyy HH:mm:ss");
            refreshOrderService.refresh(start,end,null);
            log.info("同步订单数据 Order");
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    public void refreshSendgoodsOrder() {
        try {
        String start = "01/01/2018 00:00:01";
        String end = DateUtil.getDayStr("MM/dd/yyyy HH:mm:ss");
            refreshOrderService.refresh(null,null,"WAIT_SELLER_SEND_GOODS");
            log.info("同步要发货订单数据 Order");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    //@Scheduled(cron="0  0  12 * * ?")
    public void refreshOrderStatus() {
        // 间隔12小时,执行商品同步
        try {
        refreshOrderStatus.refresh();
        log.info("同步订单状态数据 OrderStatus");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void refreshExceptionOrder(){
    	refreshOrderException.refreshOrderException();
    	 log.info("同步缺失订单状态数据");
    }
    
    
    public static void main(String[] args) {
    	Calendar now =Calendar.getInstance();
    	now.set(Calendar.DATE, now.get(Calendar.DATE)-10);
    	System.out.println(now.getTime().toLocaleString());
	}
}
